package com.yima.baseproj.module.sys.kindergarten;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yima.baseproj.aop.log.Logging;
import com.yima.baseproj.module.config.utils.PageUtil;
import com.yima.baseproj.module.config.utils.PageVo;

import com.yima.baseproj.module.config.utils.ResultUtil;
import com.yima.baseproj.module.config.utils.ResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;



@Api(tags = "幼儿园管理")
@RequestMapping("/api/sys/kg")
@RestController
public class KindergartenController {

    @Autowired
    private KindergartenService kindergartenService;

    @Logging(tags = "幼儿园管理",value = "查询分页")
    @PreAuthorize("hasAuthority('sys:kg:findAllByPage')")
    @ApiOperation("查询分页")
    @GetMapping("/findAllByPage")
    public Object findAllByPage(PageVo page, KindergartenEntity searchModel) {
        Page<Map> pageData = kindergartenService.findAllByPage(PageUtil.initMpPage(page),searchModel);
        return pageData;
    }

    @Logging(tags = "幼儿园管理",value = "添加")
    @PreAuthorize("hasAuthority('sys:kg:add')")
    @ApiOperation("添加")
    @PostMapping("/add")
    public void saveUser(@RequestBody @Validated KindergartenEntity kg) {
        kindergartenService.add(kg);
    }


    @ApiOperation("根据id查询幼儿园信息")
    @GetMapping("/findById/{id}")
    public KindergartenEntity findById(@PathVariable int id){
        KindergartenEntity kindergartenEntity = kindergartenService.findById(id);
        return kindergartenEntity;
    }

    @Logging(tags = "幼儿园管理",value = "修改")
    @PreAuthorize("hasAuthority('sys:kg:edit')")
    @ApiOperation("修改")
    @PostMapping("/edit")
    public void editKg(@RequestBody @Validated KindergartenEntity kg) {
        kindergartenService.edit(kg);
    }

    @Logging(tags = "幼儿园管理",value = "删除")
    @PreAuthorize("hasAuthority('sys:kg:delByIds')")
    @ApiOperation("删除")
    @DeleteMapping(value = "/delByIds/{ids}")
    public void delByIds(@PathVariable int ids) {

        kindergartenService.delByIds(ids);
    }


    @PreAuthorize("hasAuthority('sys:kg:findAllByList')")
    @ApiOperation("查询列表")
    @GetMapping("/findAllByList")
    public ResultVo getKg(KindergartenEntity kg) {
        List<Map> kgList = kindergartenService.findAllByList(kg);
        return ResultUtil.success(kgList);
    }
}
